package org.example;

public class Test4 {
    //leetcode 98 验证二叉搜索树 https://leetcode.cn/problems/validate-binary-search-tree/description/
    public long prev;
    public boolean isValidBST(TreeNode root) {
        prev = (long) Integer.MIN_VALUE- 1;
        return isValidBSTChild(root);
    }

    public boolean isValidBSTChild(TreeNode root) {
        if (root == null) return true;
        boolean leftRet = isValidBSTChild(root.left);
        if (!leftRet) return false;
        if (root.val <= prev) return false;
        prev = root.val;
        return isValidBSTChild(root.right);
    }

    public static void main(String[] args) {
        TreeNode a = new TreeNode(2);
        TreeNode b = new TreeNode(1);
        TreeNode c = new TreeNode(3);
        a.left = b;
        a.right = c;
        Test4 test4 = new Test4();
        test4.isValidBST(a);
        System.out.println(999);
    }
}
